package com.dianxin.smartpark.web.access;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.chinatelecom.response.common.CommonResponseBody;
import com.dianxin.device.api.device.dto.SmartDeviceUserDTO;
import com.dianxin.device.api.device.qo.SmartDeviceUserRpcQO;
import com.dianxin.smartpark.service.access.SmartParkDeviceUserService;
import com.dianxin.sso.client.annotation.RecordLog;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备授权
 * @Author wangkai
 * @Date 2021/7/29 10:18 上午
 */
@RestController
@RequestMapping("/smartpark/access/")
public class SmartParkDeviceAccessController {

    @Resource
    private SmartParkDeviceUserService smartParkDeviceUserService;

    /**
     * 查询设备用户授权列表
     *
     * @param qo qo
     * @return
     */
    @RequestMapping("/getDevicesUsers")
    @RecordLog(name = "查询设备用户授权列表")
    @SaCheckPermission("/smartpark/access/getDevicesUsers")
    public CommonResponseBody<List<SmartDeviceUserDTO>> getDevicesUser(@RequestBody SmartDeviceUserRpcQO qo) throws Exception {

        return smartParkDeviceUserService.getDevicesUsers(qo);
    }

    /**
     * 保存设备用户授权
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RecordLog(name = "保存设备用户授权")
    @SaCheckPermission("/smartpark/access/saveDeviceUser")
    @RequestMapping("/saveDeviceUser")
    public CommonResponseBody<Boolean> saveDeviceUser(@RequestBody SmartDeviceUserDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceUserService.saveDeviceUser(smartDeviceDTO);
    }

    /**
     * 更新设备用户授权
     *
     * @param smartDeviceDTO smartDeviceDTO
     * @return
     */
    @RequestMapping("/updateDeviceUser")
    @RecordLog(name = "更新设备用户授权")
    @SaCheckPermission("/smartpark/access/updateDeviceUser")
    public CommonResponseBody<Boolean> updateDevice(@RequestBody SmartDeviceUserDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceUserService.updateDeviceUser(smartDeviceDTO);
    }

    /**
     * 删除设备用户授权
     *
     * @param smartDeviceDTO smartDeviceDTO 参数只需要传id和租户id
     * @return
     */
    @RequestMapping("/delDeviceUser")
    @RecordLog(name = "删除设备用户授权")
    @SaCheckPermission("/smartpark/access/delDeviceUser")
    public CommonResponseBody<Boolean> delDevice(@RequestBody SmartDeviceUserDTO smartDeviceDTO) throws Exception {

        return smartParkDeviceUserService.deleteDeviceUser(smartDeviceDTO);
    }

}
